package interface_class;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/9/18 21:25
 */
public class Person implements Cloneable{
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void showPer(){
        System.out.println(this.name+":"+this.age);
    }
    public Person clone(){
        Person per = null;
        try {
            //Object类自带的方法，但是需要实现Cloneable标记接口
            per = (Person)super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return per;
    }

    public static void main(String[] args) {
        Person person =new Person("wewe",18);
        //这个不是对象克隆，是两个引用指向同一个对象
        Person person2 = person;
        //调用拷贝方法，两个对象，内容相同
        Person person1 = person.clone();
        System.out.println(person);
        System.out.println(person1);
        person.showPer();
        person1.showPer();
    }
}
